package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@Api("店铺状态管理相关接口")
@RestController
@RequestMapping("/admin/shop")
@Slf4j
public class ShopController {
    //店铺状态 0：打样，1：营业
    public static final String SHOP_STATUS = "SHOP_STATUS";
    @Autowired
    RedisTemplate redisTemplate;

    /**
     * 设置店铺的营业状态
     *
     * @param status
     * @return
     */
    @PutMapping("{status}")
    @ApiOperation("设置店铺状态")
    public Result setStatus(@ApiParam("店铺状态") @PathVariable Integer status) {
        log.info("店铺要设置的状态是=>{}", status == 1 ? "营业中" : "打样");

        redisTemplate.opsForValue().set(SHOP_STATUS, status);
        return Result.success();
    }


    /**
     * 获取店铺的营业状态
     *
     * @return
     */
    @GetMapping("status")
    @ApiOperation("获取店铺状态")
    public Result getStatus() {
        return Result.success(redisTemplate.opsForValue().get(SHOP_STATUS));
    }
}

